package com.ror.java.se.io;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

public class Demo12Serialize {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        SerializableStudent ss1 = new SerializableStudent("张三", 23, "南京");
        SerializableStudent ss2 = new SerializableStudent("李四", 21, "重庆");
        SerializableStudent ss3 = new SerializableStudent("王五", 22, "北京");
        ArrayList<SerializableStudent> sss = new ArrayList<>();
        Collections.addAll(sss, ss1, ss2, ss3);

        File serializedFile = new File("assets/io/serialize/stu.serialized");
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(serializedFile));
        oos.writeObject(sss);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(serializedFile));
        ArrayList<SerializableStudent> sssi = (ArrayList<SerializableStudent>) ois.readObject();
        System.out.println(sssi);
        ois.close();
    }
}
